package com.ruoyi.business.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.business.domain.JtMyDevices;
import com.ruoyi.business.service.IJtMyDevicesService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 我的设备Controller
 * 
 * @author Alan Zhang
 * @date 2025-03-29
 */
@Controller
@RequestMapping("/business/devices")
public class JtMyDevicesController extends BaseController
{
    private String prefix = "business/devices";

    @Autowired
    private IJtMyDevicesService jtMyDevicesService;

    @RequiresPermissions("business:devices:view")
    @GetMapping()
    public String devices()
    {
        return prefix + "/devices";
    }

    /**
     * 查询我的设备列表
     */
    @RequiresPermissions("business:devices:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(JtMyDevices jtMyDevices)
    {
        startPage();
        List<JtMyDevices> list = jtMyDevicesService.selectJtMyDevicesList(jtMyDevices);
        return getDataTable(list);
    }

    /**
     * 导出我的设备列表
     */
    @RequiresPermissions("business:devices:export")
    @Log(title = "我的设备", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(JtMyDevices jtMyDevices)
    {
        List<JtMyDevices> list = jtMyDevicesService.selectJtMyDevicesList(jtMyDevices);
        ExcelUtil<JtMyDevices> util = new ExcelUtil<JtMyDevices>(JtMyDevices.class);
        return util.exportExcel(list, "我的设备数据");
    }

    /**
     * 新增我的设备
     */
    @RequiresPermissions("business:devices:add")
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存我的设备
     */
    @RequiresPermissions("business:devices:add")
    @Log(title = "我的设备", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(JtMyDevices jtMyDevices)
    {
        return toAjax(jtMyDevicesService.insertJtMyDevices(jtMyDevices));
    }

    /**
     * 修改我的设备
     */
    @RequiresPermissions("business:devices:edit")
    @GetMapping("/edit/{deviceId}")
    public String edit(@PathVariable("deviceId") Long deviceId, ModelMap mmap)
    {
        JtMyDevices jtMyDevices = jtMyDevicesService.selectJtMyDevicesByDeviceId(deviceId);
        mmap.put("jtMyDevices", jtMyDevices);
        return prefix + "/edit";
    }

    /**
     * 修改保存我的设备
     */
    @RequiresPermissions("business:devices:edit")
    @Log(title = "我的设备", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(JtMyDevices jtMyDevices)
    {
        return toAjax(jtMyDevicesService.updateJtMyDevices(jtMyDevices));
    }

    /**
     * 删除我的设备
     */
    @RequiresPermissions("business:devices:remove")
    @Log(title = "我的设备", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(jtMyDevicesService.deleteJtMyDevicesByDeviceIds(ids));
    }
}
